package com.mzpai.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.Consts;
import org.apache.http.client.HttpClient;

public class MsgUtils {
	
	/** 产品密钥ID，产品标识 */
    private final static String SECRETID = "dd8bc89f6cfccc53e4648233270d1920";
    /** 产品私有密钥，服务端生成签名信息使用，请严格保管，避免泄露 */
    private final static String SECRETKEY = "618559dc235d0d29a505e9a628a06f36";
    /** 业务ID，易盾根据产品业务特点分配 */
    private final static String BUSINESSID = "0d49af7fbdc4440f91699d12cbad4afb";
    /** 本机认证服务身份证实人认证在线检测接口地址 */
    private final static String API_URL = "https://sms.dun.163.com/v2/sendsms";
    /** 实例化HttpClient，发送http请求使用，可根据需要自行调参 */
    private static HttpClient httpClient = HttpClientUtils.createHttpClient(100, 20, 10000, 2000, 2000);

    /**
     *
     * @param args
     * @throws Exception
     */
    public static String sendMsg(String mobile,  String msgCode) {
        Map<String, String> params = new HashMap<>();
        // 1.设置公共参数
     // 1.设置公共参数
        params.put("secretId", SECRETID);
        params.put("businessId", BUSINESSID);
        params.put("version", "v2");
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        //32随机字符串
        params.put("nonce", "dh2u81hdah129zjk2hlla118s0ebd2q1");
        // 2.设置私有参数d
        params.put("params", "{\"smsCode\":\"" + msgCode + "\"}");
        
        params.put("mobile", mobile);
        //使用JSON格式填充模板
        params.put("paramType", "json");
        
        params.put("templateId", "15442");
        // 2.生成签名信息
        String signature = SignatureUtils.genSignature(SECRETKEY, params);
        params.put("signature", signature);

        // 3.发送HTTP请求，这里使用的是HttpClient工具包，产品可自行选择自己熟悉的工具包发送请求
        return HttpClientUtils.sendPost(httpClient, API_URL, params, Consts.UTF_8);

    }
    
    public static void main(String[] args) {
    	String smt = "";
    	for(String s : smt.split(",")) {
    		sendMsg(s, "1299");
    	}
	}

}
